#encoding=utf-8
'''
Created on 2013-2-19

@author: Administrator
'''
from actionModule.handle import base
from base.dbCommon import getPage, getLimit, convertToArray


formJson = [
      {'id':'id', 'key':'Hidden', 'name':'主键'},
      {'id':'name', 'key':'Input', 'name':'任务名称', 'noNull':True},
      {'id':'content', 'key':'Textarea', 'name':'内容', 'noNull':True},
      {'id':'priority', 'key':'Input', 'name':'优先级', 'noNull':True},
      {'id':'schedule', 'key':'Input', 'name':'进度', 'noNull':True},
      {'key':'Submit', 'action':'planHandle.create','back':'closeTab'},
]
class planHandle(base):
    '''
    classdocs
    '''
    def __init__(self):
        self.formJson=formJson
    
    def query(self):
        qryName = self.getByKey("name")
        page = getPage(self.request)
        limit = getLimit(page)
        retBean = None
        if qryName:
            retBean = self.table.objects.filter(name__icontains=qryName).order_by('priority')
        else:
            retBean = self.table.objects.all().order_by('priority')
        
        total=retBean.count()
        retBean = retBean[limit.get("start"):limit.get("end")]
        return {'total':total,'rows':convertToArray(retBean.values())} 